import { defineStore } from 'pinia'
import { tokenUserClass, type userDataInfo } from '@/page/types/admin/user'
import { getUserInfo } from '@/api/admin'

export const userStore = defineStore('userStore', {
  state: () => ({
    isHaveUser: false,
    userInfo: {} as userDataInfo
  }),
  actions: {
    async getUser() {
      await getUserInfo().then(res => {
        if (!res) return
        this.userInfo = res.data as userDataInfo
        this.isHaveUser = true
      })
    },
    async delUser() {
      this.isHaveUser = false
      this.userInfo = new tokenUserClass().userData
    }
  },
  persist: true
})
